package com.moleq.service;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.moleq.db.DatabaseHelper;
import com.moleq.db.DatabaseSchema;
import com.moleq.models.ItemSales;
import com.moleq.models.ItemSetting;

public class ItemSalesService {
	Context mContext;
	private DatabaseHelper DBHelper;
	private SQLiteDatabase db;

	public ItemSalesService(Context context) {
		this.DBHelper = new DatabaseHelper(context,DatabaseHelper.STOCKDB_NAME);
		this.mContext = context;
	}

	public ItemSalesService(String shareDBPath) {
		this.db = SQLiteDatabase.openOrCreateDatabase(shareDBPath, null);
	}
	
	public void insert(ItemSales obj) {
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		String sql = "INSERT INTO "
				 + DatabaseSchema.ItemSales.SCHEMA_NAME + "("
				 + DatabaseSchema.ItemSales.IS_STORE_ID + ","
				 + DatabaseSchema.ItemSales.IS_STATION + ","
				 + DatabaseSchema.ItemSales.IS_TRN_NO + ","
				 + DatabaseSchema.ItemSales.IS_DATE + ","
				 + DatabaseSchema.ItemSales.IS_UPC_PLU + ","
				 + DatabaseSchema.ItemSales.IS_QTY + ","
				 + DatabaseSchema.ItemSales.IS_WEIGHT + ","
				 + DatabaseSchema.ItemSales.IS_WT_UNIT + ","
				 + DatabaseSchema.ItemSales.IS_AMT + ")"
				 + " VALUES(?,?,?,?,?,?,?,?,?)";
		 db.execSQL(
				 sql,
		 new Object[] { obj.getIs_store_id(),obj.getIs_station(),obj.getIs_trn_no(),obj.getIs_date(),obj.getIs_upc_plu(),
				 obj.getIs_qty(),obj.getIs_weight(),obj.getIs_wt_unit(),obj.getIs_amt() });
	}
	
	public void update(ItemSales obj) {
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		db.execSQL(
				"Update " + DatabaseSchema.ItemSales.SCHEMA_NAME
						+ " Set upc = ?,qty = ?,amount = ?,date = ?,trn_no = ?"
						+ ",stn_no = ? where id = ?",
				new Object[] { obj.getIs_upc_plu(),obj.getIs_qty(),obj.getIs_amt(),obj.getIs_date(),obj.getIs_trn_no(),obj.getIs_station(),obj.getIs_id() });
	}
}
